//
//@File    :	15.1_tv.h
//@Time    :	2022/02/24 19:15:07
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	Tv and Remote classes
//

#ifndef TV_H_
#define TV_H_
//电视机
class Tv
{
private:
    int state;
    int volume;
    int maxchannel;
    int channel;
    int mode;
    int input;

public:
    friend class Remote;
    enum{Off,On};//开关
    enum{MinVal,MaxVal = 20};//音量
    enum{Antenna,Cable};//有线.天线
    enum{TV,DVD};//TV或DVD
//初始化
    Tv(int s = Off, int mc = 125) : state(s), volume(5), maxchannel(mc), channel(2), mode(Cable), input(TV) {}
    void onoff(){state = (state==On)?Off:On;}
    // void onoff(){state^=1;}//简化代码
    bool ison() const{return state==On;}
    bool volup();
    bool voldown();
    void chanup();
    void chandown();
    void set_mode(){mode = (mode == Antenna)?Cable:Antenna;}
    void set_input(){input = (input==TV)?DVD:TV;}
    void settings() const;
};
//遥控器
//使用一个Tv对象引用作为参数,说明需要针对特定的电视机
class Remote
{
private:
    int mode;
public:
    Remote(int m=Tv::TV):mode(m){}
    bool volup(Tv &t){return t.volup();}
    bool voldown(Tv &t){return t.voldown();}
    bool onoff(Tv &t){t.onoff();}
    bool chanup(Tv &t){t.chanup();}
    bool chandown(Tv &t){t.chandown();}
    void set_chan(Tv &t,int c){t.channel=c;}
    void set_mode(Tv &t){t.set_mode();}
    void set_input(Tv &t){t.set_input();}
    ~Remote();
};



#endif // TV_H_